<extend name="Public/base"/>

<block name="body">
    <div class="am-cf am-u-md-12 header-title">
        <h2>导航管理</h2>
    </div>

    <div class="am-cf am-u-md-12 am-margin-top">
        <div class="am-btn-group">
            <a class="am-btn am-btn-primary" href="{:U('add','pid='.$pid)}">新 增</a>
            <button class="am-btn am-btn-danger ajax-post confirm" url="{:U('del')}" target-form="ids">删 除</button>
            <button class="am-btn am-btn-success list_sort" url="{:U('sort',array('pid'=>I('get.pid',0)),'')}">排序</button>
        </div>
    </div>

    <div class="am-cf am-u-md-12 am-margin-top">
        <div class="category">
            <div class="hd am-cf">
                <div class="fold">折叠</div>
                <div class="order">ID</div>
                <div class="order">排序</div>
                <div class="name">名称</div>
            </div>
            {:R('Channel/tree', array($list))}
        </div>
    </div>
</block>

<block name="script">
<script type="text/javascript">
    $(function() {
        //点击排序
        $('.list_sort').click(function(){
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if(ids.length > 0){
                var str = new Array();
                ids.each(function(){
                    str.push($(this).val());
                });
                param = str.join(',');
            }

            if(url != undefined && url != ''){
                window.location.href = url + '/ids/' + param;
            }
        });
    });
    (function($){
        /* 分类展开收起 */
        $(".category dd").prev().find(".fold i").addClass("icon-unfold")
            .click(function(){
                var self = $(this);
                if(self.hasClass("icon-unfold")){
                    self.closest("dt").next().slideUp("fast", function(){
                        self.removeClass("icon-unfold").addClass("icon-fold");
                    });
                } else {
                    self.closest("dt").next().slideDown("fast", function(){
                        self.removeClass("icon-fold").addClass("icon-unfold");
                    });
                }
            });

        /* 三级分类删除新增按钮 */
        $(".category dd dd .add-sub").remove();

        /* 实时更新分类信息 */
        // $(".category")
        //     .on("submit", "form", function(){
        //         var self = $(this);
        //         $.post(
        //             self.attr("action"),
        //             self.serialize(),
        //             function(data){
        //                 /* 提示信息 */
        //                 var name = data.status ? "success" : "error", msg;
        //                 msg = self.find(".msg").addClass(name).text(data.info)
        //                           .css("display", "inline-block");
        //                 setTimeout(function(){
        //                     msg.fadeOut(function(){
        //                         msg.text("").removeClass(name);
        //                     });
        //                 }, 1000);
        //             },
        //             "json"
        //         );
        //         return false;
        //     })
        //     .on("focus","input",function(){
        //         $(this).data('param',$(this).closest("form").serialize());

        //     })
        //     .on("blur", "input", function(){
        //         if($(this).data('param')!=$(this).closest("form").serialize()){
        //             $(this).closest("form").submit();
        //         }
        //     });
    })(jQuery);
</script>
</block>